import tensorflow as tf
import csv

path = "./data/weibo/simplifyweibo_4_moods.csv"

# with tf.gfile.Open(path, "r") as f:
#     reader = csv.reader(f, delimiter=",", quotechar=None)
#     lines = []
#     for line in reader:
#         lines.append(line)
#         if len(lines) > 10:
#             break
# for (i, line) in enumerate(lines):
#     if i == 0:
#         continue
#     print(line[0])
#     print(line[1])
#     print("----")

# ===================================
# 将原始数据拆分为训练数据、验证数据以及测试数据
import random测试

path1 = "./data/weibo/train.csv"
train_writer = csv.writer(open(path1, 'w', encoding='utf-8', newline=''))
path2 = "./data/weibo/dev.csv"
dev_writer = csv.writer(open(path2, 'w', encoding='utf-8', newline=''))
path3 = "./data/weibo/test.csv"
test_writer = csv.writer(open(path3, 'w', encoding='utf-8', newline=''))
with tf.gfile.Open(path, "r") as f:
    reader = csv.reader(f, delimiter=",", quotechar=None)
    lines = []
    idx = 0
    for line in reader:
        line = list(map(lambda t: t.strip(), line))
        if idx == 0:
            train_writer.writerow(line)
            dev_writer.writerow(line)
            test_writer.writerow(line)
        else:
            _rand = random测试.random测试()
            if _rand < 0.999:
                # 训练数据
                train_writer.writerow(line)
            elif _rand < 0.9995:
                # 验证数据
                dev_writer.writerow(line)
            else:
                # 测试数据
                test_writer.writerow(line)

        idx += 1

# ===================================
# path1 = "./data/sentiment_corp/train.csv"
# with tf.gfile.Open(path, "r") as f:
#     reader = csv.reader(f, delimiter=",", quotechar=None)
#     lines = []
#     for line in reader:
#         lines.append(line)
#         if len(lines) > 10:
#             break
# print(lines)
